import http from "@/utils/http";

// 导航接口
export function getCategoryAPI () {
    return http({
      url: '/home/category/head'
    })
  }
  // 首页轮播图接口
  export function getBannerAPI (params = {}) {
    const { distributionSite = '1' } = params
    return http({
      url: '/home/banner',
      params:{
        distributionSite
      }
    })
  }

  //新鲜好物
  export function getNewAPI () {
    return http({
      url: '/home/new'
    })
  }
  //人气推荐
  export function getHotAPI () {
    return http({
      url: '/home/hot'
    })
  }
// 商品
  export const getGoodsAPI = () => {
    return http({
      url: '/home/goods'
    })
  }


  // 二级分类列表

  export const getCategoryListAPI = (id) => {
    return http({
      url: '/category',
      method: 'get',
      params:{
        id
      }
    })
  }

  export const getCategoryFilterAPI = (id) => {
    return http({
      url:'/category/sub/filter',
      params:{
        id
      }
    })
  }

  /**
 * @description: 获取导航数据
 * @data { 
     categoryId: 1005000 ,
     page: 1,
     pageSize: 20,
     sortField: 'publishTime' | 'orderNum' | 'evaluateNum'
   } 
 * @return {*}
 */
export const getSubCategoryAPI = (data) => {
  return http({
    url:'/category/goods/temporary',
    method:'POST',
    data
  })
}

// 商品详情
export const getDetailAPi = (id) => {
  return http({
    url: '/goods',
    params: {
      id
    }
  })
}
/**
 * 获取热榜商品
 * @param {Number} id - 商品id
 * @param {Number} type - 1代表24小时热销榜 2代表周热销榜
 * @param {Number} limit - 获取个数
 */
export const fetchHotGoodsAPI = ({ id, type, limit = 3 }) => {
  return http({
    url:'/goods/hot',
    params:{
      id, 
      type, 
      limit
    }
  })
}